package com.gd.luxiaoyu.moduels.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gd.luxiaoyu.Constant;
import com.gd.luxiaoyu.moduels.entity.AppTableEntity;
import com.gd.luxiaoyu.moduels.service.AppTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("right/apptable")
public class AppTableController {
    @Autowired
    private AppTableService appTableService;
    Constant constant =new Constant();
    /**
     * 插入列表
     */
  @RequestMapping("/insert")
  @ResponseBody
  public R<?> Insert(AppTableEntity appTableEntity){
        boolean insert = appTableService.save(appTableEntity);
        return insert ? R.ok(constant.SUCCESSFUL):R.failed(constant.FAIL);
    }
    /*
    * 根据id删除APP
    * */
    @RequestMapping("/Delete")
    @ResponseBody
    public R<?>  Delete(AppTableEntity appTableEntity){
      boolean delete = appTableService.removeById(appTableEntity.getId());
      return  delete ? R.ok(constant.SUCCESSFUL):R.failed(constant.FAIL);
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R<?> update(AppTableEntity appTable){
        boolean update = appTableService.updateById(appTable);
        return update ? R.ok(constant.SUCCESSFUL):R.failed(constant.FAIL);
    }

    /*
    * 查询所有的APP信息
    * */
    @RequestMapping("queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(Page<AppTableEntity> appTableEntityPage,AppTableEntity appTableEntity){
        IPage<AppTableEntity> allAppInfo= appTableService.getAllAppInfo(appTableEntityPage,appTableEntity);
        Map<String,Object> map = new HashMap<>();
        map.put("Toals",allAppInfo.getTotal());
        map.put("Rows",allAppInfo.getRecords());
        return  map;
    }

    /*
    通过APP的id进行查询
    */
     @RequestMapping("queryById")
     @ResponseBody
    public AppTableEntity queryByid(AppTableEntity appTableEntity){
         AppTableEntity queryByid = appTableService.getById(appTableEntity.getId());
         return queryByid;
    }

}
